<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
     <div class="img"></div>
</body>
<script>

    function timeout(ms){
        return new Promise((resolve,reject) => {
           setTimeout(resolve,ms,'done');
        }) 
    }
    timeout(100).then((value) =>{
        console.log(value);
    })//done
    //---------------------------------------------------
    let p1 = new Promise(function(resolve,reject){
        console.log('Promise');
        resolve();
    })
    p1.then(function(){
        console.log('resolved!')
    })
    console.log('Hi');

    //Promise
    //Hi
    //resolved
   //-----------------------------------------------------
   const p3 = new Promise(function(resolve,reject){
       setTimeout(()=>reject(new Error('fail')),3000)
   })
   const p4 = new Promise(function(resolve,reject){
       setTimeout(()=>resolve(p3),1000)
   })
   p3.then(result => console.log(result))
   .catch(error => console.log(error))
   //-------------------------------------------------------   
   //reject()方法等同于抛出错误 如果Promise状态已变成resolved 再抛出错误是无效的
   //且Promise对象的错误具有冒泡性质 会一直向后传递 直到被捕获为止
   //错误总会被下一个catch语句捕获
   //一般来说，不要在then()方法里定义Reject状态的回调函数 总是使用catch方法
   //--------------------------------------------------------





</script>
</html>